package com.example.administrator.x3picturetransliteration.Home.Adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.Base.BaseListViewAdapter;
import com.example.administrator.x3picturetransliteration.Bean.BuyingMembersBean;
import com.example.administrator.x3picturetransliteration.R;

import java.math.BigDecimal;
import java.util.List;

/**
 * 购买会员
 * Created by Administrator on 2019/8/27.
 */

public class BuyingMembersAdapter extends BaseListViewAdapter{

    private List<BuyingMembersBean> mData;
    private Context context;

    private hd mhd;

    public BuyingMembersAdapter(Context context,List<BuyingMembersBean> mData,hd mhd) {
        super(context);

        this.mData = mData;
        this.context = context;

        this.mhd = mhd;
    }

    @Override
    public int getLayoutView() {
        return R.layout.home_item_buying_members;
    }

    @Override
    public int mCount() {
        return mData.size();
    }

    @Override
    public void logic(ViewHolder mViewHolder, View view, final int position) {

        IViewHolder mIViewHolder = (IViewHolder)mViewHolder;

        if ("1".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString() + "/月");

        }else if ("6".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString().toString() + "/半年");

        }else if ("12".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString().toString() + "/一年");

        }else if ("24".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString().toString() + "/两年");

        }else if ("9999".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString().toString() + "/永久");

        }else if("0".equals(mData.get(position).getType())){

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString() + "/次");

        }else {

            mIViewHolder.jgText.setText("￥" + (mData.get(position).getPrice().divide(new BigDecimal("100"))).toString() + "/" + mData.get(position).getType() + "月");
        }


        mIViewHolder.ljgmText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mhd.hdff(mData.get(position).getType());
            }
        });

    }

    @Override
    public ViewHolder InstantiationView(View mview) {

        IViewHolder mIViewHolder = new IViewHolder();

        mIViewHolder.ljgmText = mview.findViewById(R.id.ljgmText);
        mIViewHolder.jgText = mview.findViewById(R.id.jgText);

        return mIViewHolder;
    }

    private class IViewHolder extends ViewHolder{

        TextView ljgmText; //立即购买
        TextView jgText; //价格

    }

    public interface hd{

        void hdff(String type);
    }
}
